package com.jinzecloud.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinzecloud.blog.bean.Detail;
import com.jinzecloud.blog.bean.Tag;
import com.jinzecloud.blog.mapper.DetailMapper;
import com.jinzecloud.blog.service.DetailService;
import com.jinzecloud.blog.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

@Service
public class DetailServiceImpl extends ServiceImpl<DetailMapper, Detail> implements DetailService {

    @Autowired
    DetailMapper detailMapper;

    @Override
    public void add(Detail detail) {
        detailMapper.insert(detail);
    }

    @Override
    public void updateDetail(Detail detail) {
        UpdateWrapper<Detail> updateWrapper = new UpdateWrapper<Detail>().eq("d_id", detail.getDId());
        detailMapper.update(detail,updateWrapper);
    }

    @Override
    public void deleteDetail(Long[] ids) {
        //java.util.Collection<? extends java.io.Serializable>;
        detailMapper.deleteBatchIds(Arrays.asList(ids));
    }

    @Override
    public Detail getByIdDetail(Long id) {
        Detail detail = detailMapper.selectById(id);
        return detail;
    }

    @Override
    public Page<Detail> getAllDetail() {
        QueryWrapper<Detail> wrapper = new QueryWrapper<>();
        List<Detail> details = detailMapper.selectList(wrapper);
        Page<Detail> page = new Page<>(details,0,0,0);
        return page;
    }
}
